import { Component,Injector } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { BasePage } from '../../../basePage';
import { StorageService } from './../../../../providers/StorageService';
import {  nailerService } from './../../../../providers/nailerService';
declare var $: any
/**
 * Generated class for the RecordePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-recorde',
  templateUrl: 'recorde.html',
})
export class RecordePage extends BasePage{

  userinfo:{}   //读取的用户信息
  btn=[{fenlei:"提现中",select:true},{fenlei:"已提现",select:false}]
  list=[];   //提现列表
  kindList=[];  //左右列表
  types=""    //从上页面传来的身份
  general_income=0;  //总收入
  withdraw_income=0;   //已提现

  constructor(injector: Injector,public nailerService: nailerService,public stc: StorageService) {
    super(injector);
    this.userinfo = this.stc.read('userinfo');
    //默认选择提现中
    $(".category p").eq(0).addClass("add");
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad RecordePage');
    console.log(this.btn);
    this.types = this.navParams.get("types")
    console.log(this.types);
    if(this.types == "美甲师"){
       this.getList(1);
    }else if(this.types == "美甲店主"){
      this.getList(2);
    }
  }
  ionViewWillEnter(){
    //默认选择提现中
    $(".category p").eq(0).addClass("add");
  }
  // dismissCLI() {
  //   this.viewCtrl.dismiss();
  // }
  /**
   * 点击提现中和已提现切换列表
   * @param i 选择了哪一项
   */
  change(i){
    this.kindList=[];
    this.btn.forEach((e,j)=>{
      console.log(j)
      e.select=false;
      $(".category p").eq(j).removeClass("add");
    })
    this.btn[i].select=true;
    $(".category p").eq(i).addClass("add");
    console.log(this.btn)
    if(i == 0){
      console.log("提现中");
      this.other(0);
    }else if(i == 1){
      console.log("已提现");
      this.other(1);
      
    }
    
  }
  async getList(i){
    this.kindList=[];
    let param={user_id:this.userinfo['user_id'],payee_type:i}
    console.log(param)
    let result=await this.nailerService.cashBalanceAPI(param);
    console.log(result)
    if(result.code == 1){
      this.list=result.data.withdraw_list;
      this.general_income=result.data.general_income;
      this.withdraw_income=result.data.withdraw_income;
      if(this.btn[0].select == true){
        this.other(0);
      }else{
        this.other(1);
      }
    }else{
      let toast = this.toastCtrl.create({
        message: result.msg,
        duration: 1500,
        position: 'bottom'
      });
      toast.present();
    }
  }
  //查看提现中和已提现
  other(i){
    this.list.forEach((e)=>{
      if(e.pass_flag == i){
         this.kindList.push(e);
      }
    })
  }
}
